var express = require('express');
var   router   = express.Router();
const jwt      = require('jsonwebtoken');
const dataCtrl = require('../controllers/user.controller');


function verfyToken(req,res,next){
    const bearerHeader = req.headers['authorization']
    if(typeof(bearerHeader)!=='undefined'){
        const bearer      = bearerHeader.split(' ');
        const bearerToken = bearer[1];
        jwt.verify(bearerToken,'secretString',(err,authData)=>{
            if(err){
                res.sendStatus(403);
            }else{
                next()
            }
        })
    }else{
        res.sendStatus(403)
    }
}

router.post('/', dataCtrl.create);
router.put('/:id', dataCtrl.update);
router.get('/:id', dataCtrl.get);
router.delete('/:id', dataCtrl.remove);
// router.post('/list', verfyToken,dataCtrl.list);
router.post('/list',dataCtrl.list);
router.post('/search/:name', dataCtrl.search);
router.post('/removes', dataCtrl.removes);
router.post('/login', dataCtrl.login);



module.exports = router;